package com.bolingcavalry.crm.sales.controller;

import com.base.ResponseResult;
import com.bolingcavalry.crm.sales.service.SalesService;
import com.dto.SalesOrderDTO;
import com.vo.SalesOrderVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sales")
public class SalesController {
    @Autowired
    private SalesService salesService;
    //新增销售订单（销售参数）
    @PostMapping("/add")
    @ApiOperation(value = "新增销售订单")
    public ResponseResult addSalesOrder(@RequestBody SalesOrderDTO salesOrderDTO){
        Boolean aBoolean = salesService.addSelsOrder(salesOrderDTO);
        //todo 消息流转 技术负责人 销售人员 生产负责人意见 批准人意见
        if(!aBoolean){
            return ResponseResult.error("新增销售订单失败");
        }
        return ResponseResult.success("新增销售订单成功");
    }
    //查看销售订单get
    @GetMapping("/get/{id}")
    @ApiOperation(value = "查看具体的销售订单")
    public ResponseResult getSalesOrder(@PathVariable("id") Long id){
        SalesOrderVO salesOrderVo = salesService.getSalesOrder(id);
        return ResponseResult.success(salesOrderVo);
    }


    //新增合同（合同参数）
    //修改销售订单
    @PostMapping("/update")
    @ApiOperation(value = "修改销售订单")
    public ResponseResult updateSalesOrder(@RequestBody SalesOrderDTO salesOrderDTO){
        Boolean aBoolean = salesService.updateSalesOrder(salesOrderDTO);
        if(!aBoolean){
            return ResponseResult.error("修改销售订单失败");
        }
        return ResponseResult.success("修改销售订单成功");
    }
    //修改合同
    //删除销售订单
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除销售订单")
    public ResponseResult deleteSalesOrder(@PathVariable("id") Long id){
        Boolean aBoolean = salesService.deleteSalesOrder(id);
        if(!aBoolean){
            return ResponseResult.error("删除销售订单失败");
        }
        return ResponseResult.success("删除销售订单成功");
    }
    //删除合同
    //查看合同
    //分页条件查询销售订单（根据销售日期time 销售订单编号 客户id 产品 配件 状态（已完结、编辑中））
    @PostMapping("/selectpage")
    @ApiOperation(value = "分页条件查询销售订单")
    public ResponseResult selectPage(@RequestBody SalesOrderDTO salesOrderDTO){
        return ResponseResult.success(salesService.selectPage(salesOrderDTO));
    }

    //分页条件查询合同
    //打印销售订单（poi依赖） 打印按钮-展示当前销售订单信息-再次点击打印-调用打印机（poi依赖）

    //打印合同
}
